package Interfaz;

import Controladores.Mesa;
import Controladores.Orden;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Adrian
 */
public class ComerAqui extends Ventana_Defaults {

    /**
     * Creates new form ComerAqui
     */
    Orden orden;
    String comenzales1;
    ResultSet rs;
    Mesa mesa;
    int idOrden;
    int dif;
    String idMesa;
    public ComerAqui(String comenzales) {
        try {
            initComponents();
            setSize(570, 520);
            orden = new Orden();
            mesa = new Mesa();
            setLocationRelativeTo(null);
            setResizable(false);
            setTitle("Para comer aqui");
            comenzales1 = comenzales;
            rs = mesa.mesasDisponibles(comenzales);
            while(rs.next()){
                cmbMesas.addItem(rs.getString("idMesa"));
            }} catch (SQLException ex) {
            Logger.getLogger(ComerAqui.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }
    
    public ComerAqui(String idMesa1,int i) {
            idMesa = idMesa1;
        try {
            initComponents();
            setSize(570, 520);
            orden = new Orden();
            mesa = new Mesa();
            setLocationRelativeTo(null);
            setResizable(false);
            setTitle("Para comer aqui");
            rs = mesa.realizarConsulta("select capacidadComezales from mesa where idMesa="+idMesa+";");
            rs.next();
            comenzales1 =rs.getString("capacidadComezales");
            dif=1;
            
            if(i==0){
                cmbMesas.setVisible(false);
            }
        } catch (SQLException ex) {
            Logger.getLogger(ComerAqui.class.getName()).log(Level.SEVERE, null, ex);
        }
       
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        txtChiles = new javax.swing.JTextField();
        txtMole = new javax.swing.JTextField();
        txtPozole = new javax.swing.JTextField();
        txtTacos = new javax.swing.JTextField();
        txtTamarindo = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtComentarios = new javax.swing.JTextArea();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        cmbMesas = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);

        jLabel1.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jLabel1.setText("Mesas Disponibles");
        getContentPane().add(jLabel1);
        jLabel1.setBounds(102, 46, 130, 28);

        jButton2.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jButton2.setText("Atras");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(10, 5, 70, 27);

        jLabel2.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jLabel2.setText("Orden:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(197, 106, 44, 19);

        jLabel3.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jLabel3.setText("Cantidad de platillos");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(400, 70, 128, 19);

        txtChiles.setText("0");
        getContentPane().add(txtChiles);
        txtChiles.setBounds(427, 97, 43, 20);

        txtMole.setText("0");
        getContentPane().add(txtMole);
        txtMole.setBounds(427, 137, 43, 20);

        txtPozole.setText("0");
        getContentPane().add(txtPozole);
        txtPozole.setBounds(428, 179, 42, 20);

        txtTacos.setText("0");
        getContentPane().add(txtTacos);
        txtTacos.setBounds(427, 220, 43, 20);

        txtTamarindo.setText("0");
        getContentPane().add(txtTamarindo);
        txtTamarindo.setBounds(427, 261, 43, 20);

        txtComentarios.setColumns(20);
        txtComentarios.setRows(5);
        txtComentarios.setText("5mentarios");
        jScrollPane1.setViewportView(txtComentarios);

        getContentPane().add(jScrollPane1);
        jScrollPane1.setBounds(247, 301, 260, 96);

        jLabel4.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jLabel4.setText("Comentarios:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(150, 300, 90, 19);

        jButton1.setFont(new java.awt.Font("AR CENA", 0, 14)); // NOI18N
        jButton1.setText("Hacer pedido");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(403, 440, 120, 27);

        jLabel6.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 12)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("Tamarindo enmolado");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(260, 260, 150, 20);

        jLabel7.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 12)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(255, 255, 255));
        jLabel7.setText("Tacos Bisteck");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(290, 220, 100, 20);

        jLabel8.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 12)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 255, 255));
        jLabel8.setText("Pozole");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(290, 180, 100, 20);

        jLabel9.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 12)); // NOI18N
        jLabel9.setForeground(new java.awt.Color(255, 255, 255));
        jLabel9.setText("Mole");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(290, 140, 100, 20);

        jLabel11.setFont(new java.awt.Font("Microsoft Sans Serif", 1, 12)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 255, 255));
        jLabel11.setText("Chiles en rajas");
        getContentPane().add(jLabel11);
        jLabel11.setBounds(290, 100, 100, 20);
        getContentPane().add(cmbMesas);
        cmbMesas.setBounds(240, 50, 160, 20);

        jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/comida.jpg"))); // NOI18N
        jLabel5.setText("jLabel5");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(0, 0, 570, 550);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        try {
            orden.agregarOrden(comenzales1, txtChiles.getText(), txtMole.getText(), txtPozole.getText(), txtTacos.getText(), txtTamarindo.getText(),txtComentarios.getText());
            rs = orden.realizarConsulta("select idOrden from orden");
            rs.afterLast();
            rs.previous();
            idOrden = rs.getInt("idOrden");
            if(dif==1){
                mesa.actualizarMesa(idMesa,String.valueOf(idOrden),1 );
            }else{
            mesa.actualizarMesa(cmbMesas.getSelectedItem().toString(),String.valueOf(idOrden),1 );
            }
        } catch (SQLException ex) {
            Logger.getLogger(ComerAqui.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.dispose();
        
    }//GEN-LAST:event_jButton1ActionPerformed

    

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbMesas;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField txtChiles;
    private javax.swing.JTextArea txtComentarios;
    private javax.swing.JTextField txtMole;
    private javax.swing.JTextField txtPozole;
    private javax.swing.JTextField txtTacos;
    private javax.swing.JTextField txtTamarindo;
    // End of variables declaration//GEN-END:variables
}
